﻿/// <reference path="../../javascript/jquery-1.8.2.js" />

var gzoom = 20;
var marker = null;
var markerlist = new Array();
var map = new BMap.Map("map_canvas"); // 创建地图实例
map.enableScrollWheelZoom();
var myGeo = new BMap.Geocoder();
var _lat = parseFloat($("#hidLat").val());
var _lng = parseFloat($("#hidLng").val());
var initpoint = new BMap.Point(_lng, _lat); // 创建点坐标

map.addControl(new BMap.NavigationControl());  //缩放工具

function setLatLng(point) {
    document.getElementById("hidLat").value = point.lat;
    document.getElementById("hidLng").value = point.lng;
    return true;
}



//外卖订单
function showorderlocal() {
    map.clearOverlays();
    markerlist.length = 0;

    var state = $("#hfstate").val();
    var _latlng = $("#hflatlng").val();
    var deliverid = $("#hfdeliverid").val();
    var orderid = $("#hforderid").val();
    var username = $("#hfusername").val();
    var address = $("#hfaddress").val();
    var shopname = $("#hfshopname").val();

    var jsonlatlng = eval("(" + _latlng + ")");
    //用户坐标
    map.removeOverlay(marker);
    var userpoint = new BMap.Point(jsonlatlng.ulng, jsonlatlng.ulat); // 创建点坐标
    var userIcon = new BMap.Icon("/images/tack.gif", new BMap.Size(33, 33), { anchor: new BMap.Size(17, 0) });
    var usermarker = new BMap.Marker(userpoint, { icon: userIcon });

    var userlabel = new BMap.Label("用户：" + username + "(" + address + ")", { offset: new BMap.Size(-28, -22) });
    userlabel.setStyle({ color: "blue", fontSize: "12px", padding: "2px 5px 2px 5px" });
    usermarker.setLabel(userlabel);

    map.addOverlay(usermarker);
    //商家坐标
    var shoppoint = new BMap.Point(jsonlatlng.slng, jsonlatlng.slat); // 创建点坐标
    var shopmarker = new BMap.Marker(shoppoint);

    var shoplabel = new BMap.Label("商家：" + shopname, { offset: new BMap.Size(-28, -22) });
    shoplabel.setStyle({ color: "blue", fontSize: "12px", padding: "2px 5px 2px 5px" });
    shopmarker.setLabel(shoplabel);


    map.addOverlay(shopmarker);


    map.centerAndZoom(userpoint, gzoom);


    switch (state) {
        case "3":
        case "6":
        case "4":
        case "5":
        case "1":
        case "2":
            {
                return;
                break;
            }
        case "7": //在地图上显示位置,用户，商家，配送员   

            if (deliverid == "0") {
                return;
            }

            showload_super("", "", "dddd");
            var url = "/admin/ajax/GetDeliverModel.aspx";
            var para = "id=" + deliverid + "&t=" + new Date().getTime();
            jQuery.ajax(
                {
                    type: "post",
                    url: url,
                    data: para,
                    success: function (msg) {
                        hideload_super('dddd');
                        //以配送员为中心
                        var deli_latlng = eval("(" + msg + ")");

                        var d_point = new BMap.Point(deli_latlng.lng, deli_latlng.lat);// 创建点坐标
                        var d_icon = new BMap.Icon("/images/marker50.png", new BMap.Size(20, 34), { anchor: new BMap.Size(10, 0) });
                        var d_marker = new BMap.Marker(d_point, { icon: d_icon });

                        var deliverlabel = new BMap.Label("配送员:"+deli_latlng.d_name + "(" + deli_latlng.ordernum + ")", { offset: new BMap.Size(-28, -22) });
                        deliverlabel.setStyle({ color: "blue", fontSize: "12px", padding: "2px 5px 2px 5px" });
                        d_marker.setLabel(deliverlabel);
                        map.addOverlay(d_marker);

                        map.addOverlay(d_marker);
                        map.panTo(d_point);
                    }
                })


            break;
    }

}


